home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Speech MPW / say.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-28  |  2.8 KB  |  120 lines  |  [TEXT/MPS ]

  1. /*** NOTE: Tabs are set to 2 in this file ***/
  2.  
  3. /*
  4.  * {
  5.  *     say - a sample program illustrating the use of MacinTalk
  6.  *               in a MPW tool.  This tool will route standard input
  7.  *               through MacinTalk.
  8.  * 
  9.  *     disclaimer: this program was written hastely and should
  10.  *                             not be thought of as a very good example
  11.  * 
  12.  *     parameters:
  13.  *         -d        debug = on
  14.  *         -m        mode = robotic
  15.  *         -r n    rate = n
  16.  *         -p n    rate = p
  17.  * 
  18.  *     example usage:
  19.  *         Directory | say        
  20.  *         
  21.  *         by Paul Mercer, 3/86
  22.  *         modified 7/87 for inclusion in MacinTalk 1.31 release
  23.  * }
  24.  *     MPW C version by J. B. Levin 9/88
  25.  */
  26.  
  27. #include    "QuickDraw.h"
  28. #include    "OSutils.h"
  29. #include    "Memory.h"
  30. #include    "Speech.h"
  31. #include    "stdio.h"
  32. #include    "strings.h"
  33. #include    "compat.h"        /* Earle Horton's LSC / MPW compatibility macros */
  34.                                                 /*   which also gain MPW users easy access to    */
  35.                                                 /*   the Pascal (or low glue) interface          */
  36.  
  37. Str255                instr;
  38. SpeechHandle    theSpeech;        /* handle to speech globals */
  39. SpeechErr            SErr;
  40. Handle                output;                /* handle to phonetic string */
  41. Boolean                debug;
  42. FOMode                theMode;
  43.  
  44. void SayIt ()
  45. {
  46.     if (debug)
  47.         printf ("Converting text to phonemes.\n");
  48.     SErr = Reader (theSpeech, instr.text, (long)instr.length, output);
  49.     if (debug)
  50.       printf ("Speaking the phonemes\n");
  51.     SErr = MacinTalk (theSpeech, output);        /* say it. */
  52. }
  53.  
  54. void MyExit ()
  55. {
  56.     if (debug)
  57.         printf ("Closing MacinTalk.\n");
  58.     SpeechOff (theSpeech);                        /* close the speech driver. */
  59.     DisposHandle (output);                        /* release the output handle */
  60. }
  61.  
  62. /*** Main program is here. ***/
  63.  
  64. main (ac, av)
  65. int            ac;
  66. char        *av[];
  67. {
  68.     int        x, y;
  69.     
  70.     if ((SErr = SpeechOn(noExcpsFiles, &theSpeech)) != 0)
  71.         printf ("Error opening MacinTalk: %d\n", SErr);
  72.     theMode = Natural;
  73.     SpeechPitch(theSpeech, 0, theMode);
  74.     debug = false;
  75.     
  76.     for (x = 1; x < ac; x++)
  77.         if (av[x][0] == '-')
  78.             switch (av[x][1])
  79.             {
  80.                 case 'D':
  81.                 case 'd':        {    debug = true;
  82.                                             break;
  83.                                         }
  84.                 
  85.                 case 'M':
  86.                 case 'm':        {    if (debug) printf ("Mode is Robotic.\n");
  87.                                             theMode = Robotic;
  88.                                             SpeechPitch (theSpeech, 0, theMode);
  89.                                             break;
  90.                                         }
  91.                                         
  92.                 case 'R':
  93.                 case 'r':        {    sscanf (av[++x], "%d", &y);
  94.                                             if (debug) printf ("Rate is %d\n", y);
  95.                                             SpeechRate (theSpeech, y);
  96.                                             break;
  97.                                         }
  98.     
  99.                 case 'P':
  100.                 case 'p':        {    sscanf (av[++x], "%d", &y);
  101.                                             if (debug) printf ("Pitch is %d\n", y);
  102.                                             SpeechPitch (theSpeech, y, NoChange);
  103.                                             break;
  104.                                         }
  105.             }        /*end switch, end if, end for*/
  106.  
  107. /********************* (I didn't try to fiddle this for this demo - /JBL)
  108.  * IF debug THEN
  109.  *     WriteLn('now disabling signals.');
  110.  * SErr := IEsighold(SIGALLSIGS);    {disable signals}
  111.  ********************/
  112.  
  113.     output = NewHandle (0);
  114.     while (gets (&instr) != NULL)
  115.     {
  116.         c2pstr (&instr);
  117.         SayIt ();
  118.     }
  119. }
  120.